
_realname=tree-sitter-vimdoc
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.0.0
pkgrel=1
pkgdesc='Vim help file grammar for tree-sitter (mingw-64)'
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/neovim/tree-sitter-vimdoc'
msys2_repository_url='https://github.com/neovim/tree-sitter-vimdoc'
msys2_references=(
  'archlinux: tree-sitter-vimdoc'
)
license=('spdx:Apache-2.0')
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-tree-sitter"
)
source=("https://github.com/neovim/${_realname}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('a639bf92bf57bfa1cdc90ca16af27bfaf26a9779064776dd4be34c1ef1453f6c')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  tree-sitter generate src/grammar.json
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  # To get around Windows not being supported
  OS='unknown' make CC='cc' LINKSHARED='-shared' PREFIX="${MINGW_PREFIX}" PARSER_URL=$url
}

package() {
  install -d "${pkgdir}${MINGW_PREFIX}/lib/tree_sitter"
  cd "${srcdir}/${_realname}-${pkgver}"
  OS='unknown' make DESTDIR="${pkgdir}" PREFIX="${MINGW_PREFIX}" install

  # To add library to neovim runtime path
  mkdir -p "${pkgdir}${MINGW_PREFIX}/lib/nvim/parser"
  cp "${pkgdir}${MINGW_PREFIX}/lib/lib${_realname}.so" "${pkgdir}${MINGW_PREFIX}/lib/nvim/parser/${_realname#tree-sitter-}.so"

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
